import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter1911/bean/cart_info_bean_result.dart';

class CartItem extends StatelessWidget {
  const CartItem({Key? key, required this.item}) : super(key: key);

  final CartInfoBeanResult item;

  //多选按钮
  Widget _cartCheckBox(CartInfoBeanResult item) {
    return Checkbox(
      value: true,
      onChanged: (bool? val) {},
      activeColor: Colors.pink,
    );
  }

  //商品图片
  Widget _cartImage(CartInfoBeanResult item) {
    return Container(
      width: ScreenUtil().setWidth(150),
      padding: const EdgeInsets.all(3.0),
      decoration:
          BoxDecoration(border: Border.all(width: 1, color: Colors.black12)),
      child: Image.network(item.images!),
    );
  }

  //商品名称
  Widget _cartGoodsName(CartInfoBeanResult item) {
    return Container(
      width: ScreenUtil().setWidth(300),
      padding: const EdgeInsets.all(10),
      alignment: Alignment.topLeft,
      child: Column(
        children: [
          Text(item.goodsName!)
          //这里要放+-按钮
        ],
      ),
    );
  }

  //商品价格
  Widget _cartPrice(CartInfoBeanResult item) {
    return Container(
      width: ScreenUtil().setWidth(150),
      alignment: Alignment.centerRight,
      child: Column(
        children: [
          Text('¥${item.price}'),
          InkWell(
            onTap: () {},
            child: const Icon(
              Icons.delete_forever,
              color: Colors.black26,
              size: 25,
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(5.0, 2.0, 5.0, 2.0),
      padding: const EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 10.0),
      decoration: const BoxDecoration(
        color: Colors.white,
        border: Border(bottom: BorderSide(width: 1, color: Colors.black12)),
      ),
      child: Row(
        children: [
          _cartCheckBox(item),
          _cartImage(item),
          _cartGoodsName(item),
          _cartPrice(item)
        ],
      ),
    );
  }
}
